from datetime import datetime

from sqlalchemy.dialects.mysql import LONGTEXT
from sqlmodel import SQLModel

from sqlalchemy import *
from sqlalchemy.orm import *
from typing import Optional
from sqlmodel import Field

from d_utils.db_init import TableNameMeta


class LawDataProduce(SQLModel, table=True, metaclass=TableNameMeta):
    __table_args__ = {'extend_existing': True}
    id: int | None = Field(default=None, primary_key=True)
    src_url: str
    type: Optional[str]
    src_html: Optional[str] = Field(default=None, sa_column=Column(LONGTEXT))
    src_markdown: Optional[str] = Field(default=None, sa_column=Column(LONGTEXT))
    src_metadata: Optional[str] = Field(default=None, sa_column=Column(LONGTEXT))
    src_links: Optional[str] = Field(default=None, sa_column=Column(LONGTEXT))
    create_time: Optional[datetime] = Field(default=datetime.now())
    update_time: Optional[datetime] = Field(default=datetime.now())


class LawChineseDataProduce(SQLModel, table=True, metaclass=TableNameMeta):
    __table_args__ = {'extend_existing': True}
    id: int | None = Field(default=None, primary_key=True)
    src_url: str
    chinese_content: Optional[str] = Field(default=None, sa_column=Column(LONGTEXT))
    law_data_produce_id: Optional[int] = Field(default=None)
